<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
require_once 'model/db.php';


?>

<h1>ha Van Tan</h1>

<form method="POST">
    Min fans<input type="text" name="min_fans"><br>
    Max fans<input type="text" name="max_fans"><br>
    Keyword <input type="text" name="keyword"><br>
    Company<select name="id_company">
        <?php foreach ($companies as $company): ?>
        <option value="<?php echo $company['id'] ?>"><?php echo $company['name']?></option>
        <?php        endforeach;?>
    </select>
    <input type="submit" name="submit">
</form>


<?php if (isset($_POST['submit'])):?>
 <?php $keyword = (double) $_POST['keyword']; ?>
 <?php $ratingMin = (double) $_POST['ratingMin']; ?>
 <?php $ratingMax = (double) $_POST['ratingMax']; ?>
<?php 
$query = "SELECT * FROM pages 
                  
                  WHERE (likes <= $max_fans)
                      AND (likes >= $min_fans)
                      AND (description LIKE '% $keyword %')
                  LIMIT 0, 10
                  ";
        $pages = getFilms($query);
    $query = "SELECT * FROM companies";
    $companies = getData($query);
?>

<?php else :?> 
<?php 
  $query = "SELECT * FROM pages limit 0,10";
        $pages = getFilms($query); 
  ?>
<?php endif; ?>

 <table>
        <tr>
            <td> profile </td>
            <td> likes </td>
        </tr>
        <?php foreach ($pages as $page):?>
            <tr>
                <td><img src="<?php echo $page['picture']?>"></td>
                <td><?php echo $page['likes'] ?></td>
                <?php // var_dump($page);die();?>
            </tr>
        <?php endforeach; ?>
    </table> 
